local sk__diancai = fk.CreateSkill {

  name = "sk__diancai",

  tags = {  },

}



sk__diancai:addEffect(fk.EventPhaseStart, {
  name = "sk__diancai",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__diancai.name) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 2, 2,
      "#sk__diancai-choose", sk__diancai.name, true)
    if #tos == 2 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos=table.map(event:getCostData(self), function(id) return room:getPlayerById(id) end)
    room:sortByAction(tos)
    local target1, target2 = tos[1], tos[2]
    local n1, n2 = 0, 0
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == target1 then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              n2 = n2 + 1
            end
          end
        elseif move.from == target2 then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              n1 = n1 + 1
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if n1 > 0 then
      target1:drawCards(n1, sk__diancai.name)
    end
    if n2 > 0 and not target2.dead then
      target2:drawCards(n2, sk__diancai.name)
    end
  end,
})

return sk__diancai